﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;

using Factonomy.AzureUtility.Core;
using Factonomy.AzureUtility.Core.Storage;
using Factonomy.AzureUtility.Core.StorageHelpers;

namespace Factonomy.AzureUtility.Controls
{
    class AccountsContextMenu : BaseContextMenu
    {
        public event NoParameterDelegate AccountAdded;

        protected virtual void OnAccountAdded()
        {
            if (AccountAdded != null)
                AccountAdded();
        }

        public AccountsContextMenu()
        {
            MenuItem itemEdit = new MenuItem();
            itemEdit.Header = "Add";
            itemEdit.Click += new System.Windows.RoutedEventHandler(OnItemAddClick);
            this.Items.Add(itemEdit);
        }

        void OnItemAddClick(object sender, RoutedEventArgs e)
        {
            try
            {
                Dialogs.ManageAccount accountDialog = new Dialogs.ManageAccount(null);
                accountDialog.AccountChanged += new NoParameterDelegate(OnAccountChanged);
                accountDialog.Owner = Application.Current.Windows[0];
                accountDialog.ShowDialog();
            }
            catch (Exception ex)
            {
                this._helper = null;
            }
        }

        public void OnAccountChanged()
        {
            this.OnAccountAdded();
            this._helper = null;
        }
    }
}
